package com.mo.controller;

import com.github.pagehelper.PageInfo;
import com.mo.model.TTran;
import com.mo.result.R;
import com.mo.service.TranService;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author mo
 * version
 */
@RestController
public class TranController {
    @Resource
    TranService tranService;
    @GetMapping("api/tran")
    @PreAuthorize(value = "hasAuthority('tran:list')")
    public R getTran(@RequestParam(value = "current", required = false) Integer current) {
        if (current == null) {
            current = 1;
        }
        PageInfo<TTran> pageInfo = tranService.getTranByPage(current);
        return R.OK(pageInfo);
    }

    @DeleteMapping("/api/tran/{id}")
    @PreAuthorize(value = "hasAuthority('tran:delete')")
    public R deleteTran(@PathVariable("id") Integer id) {
        int count= tranService.deleteTranById(id);
        return count >= 1 ? R.OK() : R.FAIL();
    }
}
